using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using Volo.Abp.AspNetCore.Mvc;
using Ebusiness_Domain.Localization;
using Volo.Abp.Validation.Localization;
//using EmbeddedResources_Test.Localizations;
using System.Reflection;
//using EmbeddedResources_Test;

namespace Ebusiness_Host.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : AbpController
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<WeatherForecastController> _logger;

        /// <summary>
        /// 本地化测试
        /// </summary>
        //public istringlocalizer
        public IStringLocalizer<MyProjectResource> stringLocalizer { get; set; }

        public IStringLocalizer<AbpValidationResource> stringLocalizer2 { get; set; }

        /// <summary>
        /// 测试打包程序dll文件
        /// </summary>
        //public IStringLocalizer<EmbeddedResourcesResource> stringLocalizer3 { get; set; }

        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
        }

        /// <summary>
        /// 测试接口
        /// </summary>
        /// <returns></returns>
        [HttpGet(Name = "GetWeatherForecast")]
        public IEnumerable<WeatherForecast> Get()
        {
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
                TemperatureC = Random.Shared.Next(-20, 55),
                Summary = Summaries[Random.Shared.Next(Summaries.Length)]
            })
            .ToArray();
        }


        /// <summary>
        /// 本地话测试
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public string LocalizationTest()
        {
            //var assembly = typeof(EmbeddedResourcesMoudule).Assembly;
            //var x = assembly.GetManifestResourceNames();
            //var fullName2 = assembly.GetManifestResourceNames()
            //        .FirstOrDefault(n => n.StartsWith("Volo.Abp.Validation")); ;
            //var fullName = assembly.GetManifestResourceNames()
            //                       .FirstOrDefault(n => n.StartsWith("EmbeddedResources_Test"));

            //if (fullName == null)
            //    throw new Exception($"Resource EmbeddedResources_Test not found.");

            //using var stream = assembly.GetManifestResourceStream(fullName)!;
            //using var reader = new StreamReader(stream);
            //var xw = reader.ReadToEnd();

            var xxx = stringLocalizer2["ThisFieldIsNotAValidPhoneNumber."];
            //var data = stringLocalizer3["Welcome_Text"];
            var appname = stringLocalizer["Welcome_Text"];
            Console.WriteLine(xxx?.Value + "xxxxxxxx");
            //Console.WriteLine(data?.Value + "xxxxxxxx");
            Console.WriteLine(appname?.Value + "xxxxxxxx");
            return "测试本地化";
        }
    }
}
